<template>
  <div>
    <a-descriptions bordered size='small' :column='4'>
      <a-descriptions-item label='单号'>
        <span v-clipboard:copy='orderForm.orderNo' v-clipboard:success='onCopy' style='cursor:pointer'>{{ orderForm.orderNo }}</span>
      </a-descriptions-item>
      <a-descriptions-item label='发货日期'>
        {{ orderForm.sendDate }}
      </a-descriptions-item>
      <a-descriptions-item label='业务员'>
        {{ orderForm.saleManName }}
      </a-descriptions-item>

      <a-descriptions-item label='业务编码'>
        {{ orderForm.businessCode }}
      </a-descriptions-item>
      <a-descriptions-item label='区域'>
        {{ orderForm.businessArea }}
      </a-descriptions-item>
      <a-descriptions-item label='部门'>
        {{ orderForm.deptName }}
      </a-descriptions-item>
      <a-descriptions-item label='单位名称'>
        <span v-clipboard:copy='orderForm.customName' v-clipboard:success='onCopy' style='cursor:pointer'>{{ orderForm.customName }}</span>
      </a-descriptions-item>
      <a-descriptions-item label='发货方式'>
        <a-tag color='purple' v-if='orderForm.sendType==1'>现款</a-tag>
        <a-tag color='purple' v-if='orderForm.sendType==2'>预收款</a-tag>
        <a-tag color='purple' v-if='orderForm.sendType==3'>资保金</a-tag>
        <a-tag color='purple' v-if='orderForm.sendType==4'>全额资信</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='资信方式' v-if='orderForm.sendType==3'>
        <a-tag color='purple' v-if='orderForm.customBondType==1'>底价</a-tag>
        <a-tag color='purple' v-if='orderForm.customBondType==2'>税金</a-tag>
        <a-tag color='purple' v-if='orderForm.customBondType==3'>底价+税金</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='附件'>
        <f-images :value='orderForm.orderImage'></f-images>
      </a-descriptions-item>
      <a-descriptions-item label='备注'>
        {{ orderForm.remark }}
      </a-descriptions-item>
    </a-descriptions>
    <a-divider orientation='left' v-if='returnList&& returnList.length>0'>回款信息</a-divider>
    <f-table ref='returnDetails' :columns='returnColumns' rowKey='paymentId' :params='queryParam' :dataSource='returnList' :showPagination='false' :multiple='false' v-if='returnList&& returnList.length>0'>

    </f-table>
    <a-divider orientation='left'>发货信息</a-divider>
    <f-table ref='orderDrugs' rowKey='orderDetailsId' :scroll='{x:true}' :showTotal='true' :tableColumns='orderDetailsColumns' handler='hyCalculateOrderDetailsListHandler' :operator='operator' :params='queryParam' :api='api.hyOrderDetails' :pageSize='80' :autoLoad='false' :showPagination='false' :multiple='false'>
       <span slot='drugType' slot-scope='text, record, index'>
        <a-tag color='#87d068' v-if='text=="ZS"'>招商</a-tag>
        <a-tag color='#108ee9' v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='action' slot-scope='text, record,index' v-if='record.rowIndex!="合计"'>
          <template>
              <a-button type='primary' @click='$refs.calcuateDrawer.showDrawer(record,true,record.drugType)' size='small'>核算</a-button>
          </template>
        </span>
    </f-table>
    <hy-order-calcuate-drawer ref='calcuateDrawer' @success='onLoad'></hy-order-calcuate-drawer>
  </div>
</template>

<script>
import api from "../../../../js/api"
import HyOrderCalcuateDrawer from "@/views/module/haiying/order/caclulate/hy_order_calculate_drawer"
import { commonMixins } from "@/core/mixins/commonMixins"

export default {
  name: "CaclulateApplyDetails",
  components: { HyOrderCalcuateDrawer },
  mixins: [commonMixins],
  data() {
    let me = this
    let isCw = this.$store.state.user.roleInfo.isCw
    let isSw = this.$store.state.user.roleInfo.isSw
    //操作按钮
    let operator = []
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      returnList: [],
      processImageVisible: false,
      loaded: false,
      saleType: "",
      order: {},
      orderForm: {},
      isCw: isCw,
      isSw: isSw,
      calculate: false,
      operator: operator,
      orderDetailsColumns: [],
      returnColumns: [{
        title: "回款银行",
        align: "center",
        dataIndex: "returnBank"
      }, {
        title: "回款账户",
        align: "center",
        dataIndex: "returnBankNo"
      }, {
        title: "回款金额",
        align: "center",
        dataIndex: "returnAmount"
      }, {
        title: "回款日期",
        align: "center",
        dataIndex: "returnDate"
      }]
    }
  },
  created() {
  },
  computed: {},
  methods: {
    setData(data) {
      if (data && data.orderId) {
        let params = {
          orderId: data.orderId,
          handlerName: "hyOrderGetHandler"
        }
        this.http.get(this, {
          url: this.api.hyorder.get,
          params: params,
          success: (me, data) => {
            this.loaded = true
            this.orderForm = data
            this.returnList = data.returnList
            this.orderDetailsColumns = this.getColumns1(data)
          }
        })
        this.queryParam.orderId = data.orderId
        this.order = data
        this.$refs["orderDrugs"].refresh(false)
      }
    },
    getColumns1(data) {
      let sendType = this.orderForm.sendType
      let deptType = this.orderForm.deptType
      let rebateState = this.orderForm.rebateState
      return [
        {
          title: "操作",
          align: "center",
          fixed: "left",
          width: "100px",
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "商品名称",
          align: "left",
          ellipsis: true,
          dataIndex: "drugsName"
        },
        {
          title: "规格",
          align: "left",
          ellipsis: true,
          length: 30,
          width: "150px",
          dataIndex: "drugsSpec"
        },
        {
          title: "批号",
          align: "left",
          ellipsis: true,
          width: "100px",
          dataIndex: "drugLotNo"
        },
        {
          title: "类型",
          align: "center",
          width: "60px",
          dataIndex: "drugType",
          scopedSlots: { customRender: "drugType" }
        },
        {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice"
        },
        {
          title: "数量",
          align: "center",
          width: "80px",
          dataIndex: "saleNum"
        },
        {
          title: "销售金额",
          align: "center",
          width: "80px",
          needTotal: true,
          dataIndex: "saleAmount"
        },
        {
          title: "成本价",
          align: "center",
          width: "70px",
          hidden: deptType != "ZS",
          dataIndex: "costPrice"
        },
        {
          title: "成本金额",
          align: "center",
          width: "70px",
          hidden: deptType != "ZS",
          dataIndex: "costAmount"
        },
        {
          title: "底价",
          align: "center",
          width: "80px",
          hidden: sendType != 3,
          dataIndex: "customFloorAmount"
        },
        {
          title: "税金",
          align: "center",
          width: "80px",
          hidden: sendType != 3,
          dataIndex: "customGapUpAmount"
        },
        {
          title: "资保金应收",
          align: "center",
          width: "80px",
          hidden: sendType != 3,
          dataIndex: "customBond"
        },
        {
          title: "部门",
          align: "center",
          hidden: deptType == "ZS",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              dataIndex: "deptPrice"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              dataIndex: "deptRate"
            },
            {
              title: "部门费用",
              align: "center",
              width: "90px",
              dataIndex: "deptSettleAmount"
            }
          ]
        },
        {
          title: "渠道商",
          align: "center",
          width: "120px",
          hidden: deptType == "ZY",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              dataIndex: "settlePrice"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              dataIndex: "settleRate"
            },
            {
              title: "结算金额",
              align: "center",
              width: "90px",
              needTotal: true,
              dataIndex: "settleAmount"
            },
            {
              title: "提成金额",
              align: "center",
              width: "90px",
              hidden:rebateState==0,
              needTotal: true,
              dataIndex: "settleRebateAmount"
            }
          ]
        }
      ]
    },
    onLoad() {
      this.$refs["orderDrugs"].refresh(false)
    },

    processImg(order) {
      this.processInstanceId = order.processInstanceId
      this.processImageVisible = true
    }
  }
}
</script>
<style lang='less'>


</style>